package cn.kgc.jihe.LinkedList01;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class StudentTest {
    public static ArrayList<Student>arr=new ArrayList<Student>();
    static {
        arr.add(new Student("张三",20,90.0F));
        arr.add(new Student("李四",22,90.0F));
        arr.add(new Student("王五",20,95.0F));
        arr.add(new Student("赵六",22,100.0F));
        arr.add(new Student("田七",26,87.0F));
    }

    public static void main(String[] args) {
        Collections.sort(arr, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = (int)(o2.getScore() - o1.getScore());
                if(result==0){
                    result = o2.getAge()-o1.getAge();
                }
                return  result;

            }
        });
        for (Student student:arr){
            System.out.println("姓名："+student.getName()+"\t\t"+"年龄："+student.getAge()+"\t\t"+"分数："+student.getScore());
        }
    }
}
